package com.leo.config;

import com.leo.annotation.ScanIgnore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

/**
 * @ClassName: WebSpringMVCServletConfig
 * @Description: Web配置类，类似以前的myspringmvc-servlet.xml
 * @Configuration 是一个类级别的注释，指示对象是bean定义的来源
 * @EnableWebMvc 就相当于导入了WebMvcConfigurationSupport类，这个时候，Spring Boot的自动装配就不会发生了，我们能用的，只有WebMvcConfigurationSupport提供的若干个配置。其实不使用@EnableWebMvc注解也是可以实现配置Webmvc，只需要将配置类继承于WebMvcConfigurationSupport类即可
 * @ComponentScan 配置扫描的包路径
 * excludeFilters: 主要是排除这两个配置的类，不然初始化的时候注册了一次，然后扫描包的时候再一次会被重复注册
 * @Author: leo825
 * @Date: 2020-05-16 21:10
 * @Version: 1.0
 */
@Configuration
@ScanIgnore
//@ComponentScan(basePackages = {"com.leo"}, excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {ApplicationContextConfig.class, WebSpringMVCServletConfig.class}))
//@ComponentScan(basePackages = {"com.leo"}, excludeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = ScanIgnore.class))
//@ComponentScan(basePackages = {"com.leo"}, excludeFilters = @ComponentScan.Filter(type = FilterType.CUSTOM, classes = MyTypeFilter.class))
@ComponentScan(basePackages = {"com.leo"}, excludeFilters = @ComponentScan.Filter(type = FilterType.REGEX, pattern = "com.leo.config.*"))
public class WebSpringMVCServletConfig extends WebMvcConfigurationSupport {
    @Bean
    public ViewResolver viewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("WEB-INF/views/");
        resolver.setSuffix(".jsp");
        return resolver;
    }
}
